package com.guaoran.other.proxy.JDK;

import com.guaoran.other.proxy.staticed.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author : 孤傲然
 * @Description :
 * @date :2018/5/17 14:33
 */
public class JDKMeiPo implements InvocationHandler {
    private Object person;
    public Object getInstance(Object target) throws Exception{
        this.person = target;

        Class<?> clazz = target.getClass();

        //用来生成一个新的对象（字节码重组来实现）
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("jdk媒婆开始");
        Object invoke = method.invoke(this.person, args);
        System.out.println("jdk媒婆结束");
        return invoke;
    }

}
